#/bin/bash

case $1 in
	auth )
		Reg="(User-Name,|User-Password,|CHAP-Password,|CHAP-Challenge,|NAS-IP-Address,|NAS-Identifier,|Called-Station-Id,|Calling-Station-Id,|Framed-IP-Address,)"
		Rg=(User-Name, User-Password, CHAP-Password, CHAP-Challenge, NAS-IP-Address, NAS-Identifier, Called-Station-Id, Calling-Station-Id, Framed-IP-Address,)
		;;
	start )
		Reg="(User-Name,|NAS-IP-Address,|NAS-Identifier,|Called-Station-Id,|Calling-Station-Id,|Acct-Status-Type,|Acct-Delay-Time,|Acct-Session-Id,|Framed-IP-Address,|Event-Timestamp,)"
		Rg=(User-Name, NAS-IP-Address, NAS-Identifier, Called-Station-Id, Calling-Station-Id, Acct-Status-Type, Acct-Delay-Time, Acct-Session-Id, Framed-IP-Address, Event-Timestamp,)
		;;
	update )
		Reg="(User-Name,|NAS-IP-Address,|NAS-Identifier,|Called-Station-Id,|Calling-Station-Id,|Acct-Status-Type,|Acct-Delay-Time,|Acct-Session-Id,|Acct-Input-Octets,|Acct-Output-Octets,|Acct-Input-Gigawords,|Acct-Output-Gigawords,|Acct-Session-Time,|Framed-IP-Address,|Event-Timestamp,)"
		Rg=(User-Name, NAS-IP-Address, NAS-Identifier, Called-Station-Id, Calling-Station-Id, Acct-Status-Type, Acct-Delay-Time, Acct-Session-Id, Acct-Input-Octets, Acct-Output-Octets, Acct-Input-Gigawords, Acct-Output-Gigawords, Acct-Session-Time, Framed-IP-Address, Event-Timestamp,)
		;;
	stop )
		Reg="(User-Name,|NAS-IP-Address,|NAS-Identifier,|Called-Station-Id,|Calling-Station-Id,|Acct-Status-Type,|Acct-Delay-Time,|Acct-Session-Id,|Acct-Input-Octets,|Acct-Output-Octets,|Acct-Input-Gigawords,|Acct-Output-Gigawords,|Acct-Session-Time,|Acct-Terminate-Cause,|Framed-IP-Address,|Event-Timestamp,)"
		Rg=(User-Name, NAS-IP-Address, NAS-Identifier, Called-Station-Id, Calling-Station-Id, Acct-Status-Type, Acct-Delay-Time, Acct-Session-Id, Acct-Input-Octets, Acct-Output-Octets, Acct-Input-Gigawords, Acct-Output-Gigawords, Acct-Session-Time, Acct-Terminate-Cause, Framed-IP-Address, Event-Timestamp)
		;;
	* )
	echo "parameter error (auth|start|update|stop)"
	echo "ex :"
	echo 'sh radius_report.sh auth "2016-10-21 16:30:15 [INFO] authPackage is (User-Name,15588488885@windfind.dynamic@igd),(CHAP-Password,0x91a6fe4fa2f867d77bfa0f7916be75e1be),(CHAP-Challenge,0xcfe45749745d818adc35ffec9fdfdc36),(NAS-IP-Address,10.0.26.252),(NAS-Identifier,Gzlib-Core-H3C-AC-1),(NAS-Port,17629392),(NAS-Port-Id,slot=1;subslot=0;port=208;vlanid=208;),(NAS-Port-Type,Wireless-802.11),(Service-Type,Framed-User),(Framed-Protocol,Ascend-ARA),(Calling-Station-Id,8C-3A-E3-94-7C-BF),(Called-Station-Id,0C-DA-41-1F-77-A0:i-Guangdong),(Acct-Session-Id,11610211630150b2236410eb28),(Framed-IP-Address,10.0.208.36),(Huawei-Connect-ID,8182),(Huawei-Product-ID,LSQ1WCMD0),(Huawei-IPHost-Addr,10.0.208.36 8c:3a:e3:94:7c:bf),(Huawei-Startup-Stamp,1464165372), "'

esac


read -p "输入报文:" var



echo ""
echo "原始报文:"
echo ${var} | sed 's/),/\n/g'

echo "匹配报文:"
echo ${var} | sed 's/),/\n/g' | grep --color -E ${Reg}
echo ""
echo "匹配结论:"
for i in `echo ${Rg[*]}`; do
	echo ${i}":" `echo ${var} | grep -cE ${i}`
done

echo ""
echo ${Reg} | awk -F'|' '{print "检查必须字段数:" NF}'
echo "检查出来实际字段数:" `echo ${var} | sed 's/),/\n/g' | grep -cE ${Reg}`
echo ""

